﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using XLua;
[LuaCallCSharp]
public class GameObjectLua
{
    public static void On()
    {

    }

    public static void Off()
    {
        Debug.Log("=========off");
    }


    public static uint Load(string bundleName, string assetName, Action<UInt32,UInt32> callback = null)
    {
        uint hadler = LoadManager.Instance.LoadPrefab(bundleName, assetName, callback);
        return hadler;
    }

    public static void UnLoad(UInt32 handleKey)
    {
        LoadManager.Instance.UnLoadPrefab(handleKey);
    }

    public static uint Register(string path)
    {
        GameObject go = GameObject.Find(path);
        if (go == null)
        {
            Debug.LogError("没有找到路径为:" + path + "的对象...");
            return 0;
        }
        else
        {
            uint skinID = ObjectManager.Instance.AddObj(go);
            return skinID;
        }

    }

    /// <summary>
    /// 复制预设
    /// </summary>
    /// <param name="objID"></param>
    /// <returns></returns>
    public static uint RegisterAndInstantiate(uint objID)
    {
        GameObject obj = ObjectManager.Instance.GetGameObject(objID);
        if (obj != null)
        {
            GameObject go = GameObject.Instantiate(obj);
            uint skinID = ObjectManager.Instance.AddObj(go);
            return skinID;
        }
        return 0;
    }

    public static uint RegisterChild(uint objID, string path)
    {
        GameObject obj = ObjectManager.Instance.GetGameObject(objID);
        if (obj != null)
        {
            GameObject go = obj.transform.FindChild(path).gameObject;
            if (go == null)
            {
                Debug.LogError("没有找到路径为:" + path + "的对象...");
                return 0;
            }
            else
            {
                uint skinID = ObjectManager.Instance.AddObj(go);
                return skinID;
            }
        }
        return 0;
    }

    public static void UnRegister(uint objID)
    {
        ObjectManager.Instance.RemoveObj(objID);
    }
}

